<!--
* description: 销退管理-销退审核
* author: ligy
* createdDate: 2020-11-24
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="ApiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
    />
  </div>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/vehicleManagement'
import lov from '@/api/Lov'

export default {
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      editPopupsState: 'edit',
      showPopupsVisible: false,
      // 指定请求类型 可以统一在 utils/config.js中配置
      apiStyle: 'restful',
      ApiConfig: api.pinBackAudit,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'saleOrderRetrunId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            // 操作
            {
              prop: '',
              label: '操作',
              width: 120,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey0',
                  labelName: '审核通过',
                  rowFileds: 'show:returnStateName-申请中(待审核)',
                  codeField: '',
                  clickEvent: (index) => {
                    this.audit(
                      this.$refs['multipleTable'].list[index],
                      'pass'
                    )
                  },
                  component: () => import('@/components/org/linkButton')
                },
                {
                  compKey: 'propKey2',
                  labelName: '驳回',
                  rowFileds: 'show:returnStateName-申请中(待审核)',
                  codeField: '',
                  clickEvent: (index) => {
                    this.audit(
                      this.$refs['multipleTable'].list[index],
                      'dismissed'
                    )
                  },
                  component: () => import('@/components/org/linkButton')
                }
              ]
            },
            {
              label: '审核说明',
              width: 140,
              prop: 'auditDesc',
              isShowLabel: false,
              isComponent: true,
              comps: [
                {
                  compKey: 'audit',
                  codeField: 'auditDesc',
                  component: () => import('@/components/org/commonInput'),
                  rowFileds: 'disabled:returnStateName-已确认(业务审核)|disabled:returnStateName-已驳回(业务审核)'
                }
              ]
            },
            {
              prop: 'saleOrderTypeName',
              label: '退货类型'
            },
            {
              prop: 'saleOrderRetrunCode',
              label: '销退申请单号'
            },
            {
              prop: 'orderDlrCode',
              label: '门店编码'
            },
            {
              prop: 'oldDlrShortName',
              label: '门店名称'
            },
            {
              prop: 'returnStateName',
              label: '状态'
            },
            {
              prop: 'applyDate',
              label: '申请日期'
            },
            {
              prop: 'creator',
              label: '申请人'
            },
            {
              prop: 'saleOrderFee',
              label: '退货总金额'
            },
            {
              prop: 'saleOrderReasonName',
              label: '退货申请原因'
            },
            {
              prop: 'saleOrderCode',
              label: '关联订单号'
            },
            { prop: 'carSeriesCn',
              label: '车系'
            },
            {
              prop: 'carConfigCn',
              label: '基础车型'
            },
            {
              prop: 'optionalPagName',
              label: '选装包'
            },
            {
              prop: 'carColorName',
              label: '车身颜色'
            },
            {
              prop: 'carIncolorName',
              label: '内饰颜色'
            }
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 退货类型
            {
              compKey: 'compKey1',
              labelName: '退货类型：',
              codeField: 'saleOrderType',
              lookuptype: 'VE0031',
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true
            },
            // 申请单号
            {
              compKey: 'compKey2',
              labelName: '销退申请单号：',
              codeField: 'saleOrderRetrunCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '关联订单号：',
              codeField: 'saleOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            // 申请日期
            {
              compKey: 'compKey4',
              labelName: '申请日期：',
              codeField: 'applyStartTime,applyEndTime',
              component: () => import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMust: true
            },
            // 门店编码
            {
              compKey: 'compKey5',
              labelName: '门店编码：',
              codeField: 'orderDlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            // 门店名称
            {
              compKey: 'compKey6',
              labelName: '门店名称：',
              codeField: 'orderDlrName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            // 状态
            {
              compKey: 'compKey7',
              labelName: '退货单状态：',
              codeField: 'returnStateCode',
              lookuptype: 'VE0033',
              component: () => import('@/components/org/commonSelect'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey8',
              labelName: '车系：',
              codeField: 'carSeriesId',
              oFields: 'carSeriesId,carSeriesCn',
              customObj: {
                api: lov.listOfCarSeries
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey9',
              labelName: '基础车型：',
              codeField: 'carConfigId',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'carConfigId,carConfigCn',
              parentFileds: 'value:carSeriesId',
              customObj: {
                api: lov.queryCarType,
                listQuery: {
                  carSeriesId: ''
                }
              },
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey10',
              labelName: '选装包：',
              codeField: 'optionalPagId',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'optionalPagId,optionalPagName',
              parentFileds: 'value:carConfigId',
              customObj: {
                api: lov.queryCarOptionalPagLinkMessage,
                listQuery: {
                  carConfigId: ''
                }
              },
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey11',
              labelName: '车身颜色：',
              codeField: 'carColorId',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'carColorId,carColorName',
              parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
              customObj: {
                listQuery: {
                  carConfigId: '', carSeriesId: '', optionalPagId: ''
                },
                api: lov.queryCarColorLinkMessage
              },
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey12',
              labelName: '内饰颜色：',
              codeField: 'carIncolorId',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'carIncolorId,carIncolorName',
              parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
              customObj: {
                listQuery: {
                  carConfigId: '', carSeriesId: '', optionalPagId: ''
                },
                api: lov.queryCarInColorLinkMessage,
                selectType: '1'
              },
              type: 'dropdownList',
              isMust: false
            }
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          size: 'small',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        saleOrderType: '',
        saleOrderRetrunCode: '',
        saleOrderCode: '',
        orderDlrCode: '',
        orderDlrName: '',
        returnStateCode: '',
        carSeriesId: '',
        carConfigId: '',
        carConfigCn: '',
        carSeriesCn: '',
        optionalPagId: '',
        carColorId: '',
        carIncolorId: '',
        applyStartTime: '',
        applyEndTime: ''
      })
    }
  },
  methods: {
    // 审核通过 驳回
    audit(curRowdata, status) {
      const loading = this.$loading({
        text: status === 'pass' ? '正在审核...' : '正在驳回...'
      })
      this.$requestAPI({
        apiUrl: status === 'pass'
          ? api.auditOrder.APIUrl
          : api.rejectOrder.APIUrl,
        variables: status === 'pass'
          ? {
            PRE_SALE_ORDER_STATE: curRowdata.PRE_SALE_ORDER_STATE,
            VEHICLE_STATUS: curRowdata.VEHICLE_STATUS,
            UPDATE_CONTROL_ID: curRowdata.UPDATE_CONTROL_ID,
            updateControlDIdO: curRowdata.updateControlDIdO,
            SALE_ORDER_ID: curRowdata.SALE_ORDER_ID,
            updateControlId: curRowdata.updateControlId,
            saleOrderCodeC: curRowdata.saleOrderCodeC,
            saleOrderRetrunId: curRowdata.saleOrderRetrunId,
            orderStatus: curRowdata.orderStatus,
            CAR_ID: curRowdata.CAR_ID,
            vin: curRowdata.vin,
            auditDesc: curRowdata.auditDesc,
            saleOrderDId: curRowdata.saleOrderDId,
            saleOrderRetrunCode: curRowdata.saleOrderRetrunCode,
            saleOrderType: curRowdata.saleOrderType,
            saleOrderFee: curRowdata.saleOrderFee,
            saleOrderReason: curRowdata.saleOrderReason,
            updateControlDId: curRowdata.updateControlDId
          } : {
            VEHICLE_STATUS: curRowdata.VEHICLE_STATUS,
            UPDATE_CONTROL_ID: curRowdata.UPDATE_CONTROL_ID,
            updateControlDIdO: curRowdata.updateControlDIdO,
            SALE_ORDER_ID: curRowdata.SALE_ORDER_ID,
            updateControlId: curRowdata.updateControlId,
            saleOrderCodeC: curRowdata.saleOrderCodeC,
            saleOrderRetrunId: curRowdata.saleOrderRetrunId,
            PRE_SALE_ORDER_STATE: curRowdata.PRE_SALE_ORDER_STATE,
            CAR_ID: curRowdata.CAR_ID,
            auditDesc: curRowdata.auditDesc,
            saleOrderDId: curRowdata.saleOrderDId,
            saleOrderRetrunCode: curRowdata.saleOrderRetrunCode,
            saleOrderType: curRowdata.saleOrderType,
            saleOrderFee: curRowdata.saleOrderFee,
            saleOrderReason: curRowdata.saleOrderReason,
            updateControlDId: curRowdata.updateControlDId
          }
      }).then(res => {
        this.$message(res.msg)
        loading.close()
        this.queryTable(1)
        // 请求成功
      }).catch(() => {
        loading.close()
      })
    },
    // 保存或新增后调用此方法
    popClose(type) {
      this.this.showPopupsVisible = false
      if (type === 1) {
        this.queryTable(1)
      }
    },
    // 新增
    edit(index) {
      this.showPopupsVisible = true
      this.editPopupsState = 'edit'
      this.editRowData = this.$refs['multipleTable'].list[index]
    }
  }
}
</script>

<style></style>
